// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
const _ = db.command



// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()

    let table = event.table
    let type = event.type

    if (table == 'signRecord' && type == 'deleteAll') {
        //删除签到记录表的所有记录
        return await db.collection('signRecord').where({
            _id: _.exists(true) //只要_id字段存在，就删除
        }).remove()
    }

    // return {
    //     event,
    //     openid: wxContext.OPENID,
    //     appid: wxContext.APPID,
    //     unionid: wxContext.UNIONID,
    // }
}